package com.gsit.expenditure.component;

import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.TableCell;

import com.gsit.expenditure.domain.Customer;
import com.gsit.expenditure.services.CustomerService;

public class DeleteTableCell<S, T> extends TableCell<S, T> {
	private final Button deleteButton;
	private final ObservableList<S> customers = FXCollections.observableArrayList();
	private ObservableValue<T> observableValue;
	private CustomerService customerService;

	public DeleteTableCell( CustomerService customerService  ) {
		this.customerService = customerService;
		//System.out.println("customersList "+customer.getFirstName());
		this.deleteButton = new Button("XXX");
		deleteButton.setStyle("-fx-base: red;");
		this.deleteButton.setAlignment(Pos.CENTER);

		setAlignment(Pos.CENTER);
		setGraphic(deleteButton);
		deleteButton.setOnAction(new EventHandler<ActionEvent>() {
			@Override
			public void handle(ActionEvent t) {
				int i = getIndex();

				if (i >= 0) {
					//customerService.delete(customersList.get(i));
					System.out.println(customers.get(getIndex()));
					System.out.println("deleted" + getIndex());
				}
				
			}
		});
	}

	@Override
	public void updateItem(T item, boolean empty) {
		super.updateItem(item, empty);
		System.out.println("empty is "+empty );
		if (empty) {
			setText(null);
			setGraphic(null);
		} else {
			setGraphic(deleteButton);
		}

		// setGraphic(deleteButton);
	}
}
